/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package es.us.gestortareas.entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author master
 */
@Entity
@Table(name = "USUARIO_TAREA")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "UsuarioTarea.findAll", query = "SELECT u FROM UsuarioTarea u"),
    @NamedQuery(name = "UsuarioTarea.findByIdUsuario", query = "SELECT u FROM UsuarioTarea u WHERE u.usuarioTareaPK.idUsuario = :idUsuario"),
    @NamedQuery(name = "UsuarioTarea.findByIdTarea", query = "SELECT u FROM UsuarioTarea u WHERE u.usuarioTareaPK.idTarea = :idTarea"),
    @NamedQuery(name = "UsuarioTarea.findByRol", query = "SELECT u FROM UsuarioTarea u WHERE u.rol = :rol")})
public class UsuarioTarea implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected UsuarioTareaPK usuarioTareaPK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "ROL")
    private String rol;
    @JoinColumn(name = "ID_USUARIO", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Usuario usuario;
    @JoinColumn(name = "ID_TAREA", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Tarea tarea;

    public UsuarioTarea() {
    }

    public UsuarioTarea(UsuarioTareaPK usuarioTareaPK) {
        this.usuarioTareaPK = usuarioTareaPK;
    }

    public UsuarioTarea(UsuarioTareaPK usuarioTareaPK, String rol) {
        this.usuarioTareaPK = usuarioTareaPK;
        this.rol = rol;
    }

    public UsuarioTarea(int idUsuario, int idTarea) {
        this.usuarioTareaPK = new UsuarioTareaPK(idUsuario, idTarea);
    }

    public UsuarioTareaPK getUsuarioTareaPK() {
        return usuarioTareaPK;
    }

    public void setUsuarioTareaPK(UsuarioTareaPK usuarioTareaPK) {
        this.usuarioTareaPK = usuarioTareaPK;
    }

    public String getRol() {
        return rol;
    }

    public void setRol(String rol) {
        this.rol = rol;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Tarea getTarea() {
        return tarea;
    }

    public void setTarea(Tarea tarea) {
        this.tarea = tarea;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (usuarioTareaPK != null ? usuarioTareaPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof UsuarioTarea)) {
            return false;
        }
        UsuarioTarea other = (UsuarioTarea) object;
        if ((this.usuarioTareaPK == null && other.usuarioTareaPK != null) || (this.usuarioTareaPK != null && !this.usuarioTareaPK.equals(other.usuarioTareaPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "es.us.gestortareas.entity.UsuarioTarea[ usuarioTareaPK=" + usuarioTareaPK + " ]";
    }
    
}
